<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>推广者管理</title>
<%@ include file="../common/importLib.jsp" %>
<link rel="stylesheet" type="text/css" href="../common/css/codeDownload.css">
<script type="text/javascript" src="../common/My97DatePicker/WdatePicker.js"></script> 
<script type="text/javascript" src="../common/jquery-cascade/js/jquery.cityselect.js"></script>
<script type="text/javascript">
	/**
	 * 增删改查参数设置
	 */
	tableTitle = "推广者列表";
	tableURL = getTimeURL("../share/distributorInfo/queryDistributorInfoPage.do");
	//toolbarView = 2;
	tableColumns = [[{field:'ck',width:30,checkbox:true,rowspan:1},
	                {field:'id',title:'id',width:0,rowspan:1},
					{field:'opt',title:'操作',width:100,align:'center', rowspan:1,
						formatter:function(value,rowData,rowIndex){	
							var queryUrl = '../share/distributorInfo/queryById.do?id=' + rowData.id;						
							return "<a title='编辑' class='xxl_linkbutton' iconCls='icon-edit' href='javascript:datagridUpdate(\"" + queryUrl + "\")'>编辑</a>";
						}
					},	
					{field:'distributorName',title:'昵称',width:120,rowspan:1},
					{field:'userMobilePhone',title:'手机号',width:100,rowspan:1},
					{field:'createTimeString',title:'开始时间',width:150,rowspan:1,
						formatter:function(value,rowData,rowIndex){
							if(rowData.distributorType == 1 || rowData.distributorType == 2){
								return rowData.upgradeTimeString;
							}else{
								return rowData.createTimeString;
							}
						}
					},
					{field:'deadlineTimeString',title:'有效截止时间',width:150,rowspan:1,
						formatter:function(value,rowData,rowIndex){
							if(rowData.distributorType == 0 || rowData.distributorType == 51
									|| rowData.distributorType == 52 || rowData.distributorType == 7){
								return "长期" ;
							}else{
								return rowData.deadlineTimeString;
							}
						}
					},
					{field:'shareCode',title:'推广码',width:100,rowspan:1},
					{field:'distributorType',title:'资格',width:100,rowspan:1,
						formatter:function(value,rowData,rowIndex){
							if(rowData.distributorType == 0){
								return "<font color='green'>【普通】</font>";
							}else if(rowData.distributorType == 1){
								return "<font color='green'>【中级分销商】</font>";
							}else if(rowData.distributorType == 2){
								return "<font color='green'>【高级分销商】</font>";
							}else if(rowData.distributorType == 3){
								return "<font color='green'>【合作方】</font>";
							}else if(rowData.distributorType == 4){
								return "<font color='red'>【过期】</font>";
							}else if(rowData.distributorType == 51){
								return "<font color='green'>【讲师】</font>";
							}else if(rowData.distributorType == 52){
								return "<font color='green'>【明师】</font>";
							}else if(rowData.distributorType == 6){
								return "<font color='green'>【服务站】</font>";
							}else if(rowData.distributorType == 7){
								return "<font color='green'>【家人团队】</font>";
							}
						}
					},
					{field:'sharingProportion',title:'分成比例',width:100,rowspan:1}
					]];
	
	var addWidth = 800; //添加窗口宽度
	var addHeight = 450; //添加窗口高度
	var addTitle = "添加推广者信息"; //添加标题
	var updateWidth = 800; //修改窗口宽度
	var updateHeight = 450; //修改窗口高度
	var updateTitle = "修改推广者信息"; //修改标题
	//var updateDisableFlagUri = "../maintain/partnerInfo/updateDisableFlag.do"; //禁用、起用记录
	//var deleteUri = "../maintain/partnerInfo/deleteByIds.do"; //删除记录
	
	/**
	 * 初始化添加表单
	 */	
	function initAddForm(){	
		
	}
	
	/**
	 * 初始化修改表单
	 */
	function initUpdateForm(jsonObject){
		$("#idUpdate").val(jsonObject.info.id);
		$("#distributorNameUpdate").html(jsonObject.info.distributorName);
		$("#shareCodeUpdate").html(jsonObject.info.shareCode);
		$("#distributorTypeUpdate").html(jsonObject.info.distributorType);
		$("#sharingProportionUpdate").val(jsonObject.info.sharingProportion);
	}
	
	//更新提交的方法
	function updateFormSubmit(){
		var params = getFormJson($('#update_form'));
		$.ajax({
			  type: 'POST',
			  url: '../share/distributorInfo/edit.do',
			  data: params,
			  dataType: 'json',
			  async: false,
			  success: function(data){
				  if(data.err_code ==0){
					  $('#datagrid_update').window('close');
					  $('#datagrid_table').datagrid('reload');
				  }else{
					  alert(data.err_msg);
				  }
			  },
			  error: function(xhr, type){
			    alert('Ajax error!')
			  }
		});
	}
	//将form中的值转换为键值对。
	function getFormJson(frm) {
	    var o = {};
	    var a = $(frm).serializeArray();
	    $.each(a, function () {
	        if (o[this.name] !== undefined) {
	            if (!o[this.name].push) {
	                o[this.name] = [o[this.name]];
	            }
	            o[this.name].push(this.value || '');
	        } else {
	            o[this.name] = this.value || '';
	        }
	    });

	    return o;
	}
	
	//覆盖默认的方法来实现自定义 加载成功后的回调函数
	function defualtOnLoadSuccess(data){
		setTimeout(function() {	
			$("#datagrid_table").datagrid("clearSelections");
			$("#datagrid_table").datagrid("clearChecked");
			$(".xxl_linkbutton").linkbutton({plain:true});
			//MathJax.Hub.Queue(["Typeset",MathJax.Hub,document.getElementsByName("body")[0]]);
		}, 10);
		//推广者总数
		$("#totalPromoterNum").html(data.totalPromoterNum);
		
	}
	
</script>
<script type="text/javascript">
</script>
</head>
<body id="layout" class="easyui-layout">
<div style="background: none repeat scroll 0% 0% #EFEFEF; height:110px; padding: 6px 2px; border-bottom: 1px solid #CCC;"
		region="north"  split="false" title="条件查询">
	<form  id="searchForm" >
	<table>
		<tr>
			<td width ="10px;"></td> <td><span style="font-size: 15px;color: red;">推广者总数：</span></td><td><span style="font-size:20px;color:green" id="totalPromoterNum">0</span><span style="font-size: 15px;color: red;">&nbsp;人</span></td>			
			<td width="30px;"></td>
			<td>昵称：</td><td><input type="text" name="distributorName"/> </td>
			<td width ="20px;"></td>
			<td >开始时间：</td><td width="360px;"><input type="text" name="startTime" id="startTime" style="width: 150px;" class="input-style" onclick="WdatePicker({el:'startTime',maxDate:'#F{$dp.$D(\'endTime\')}', dateFmt: 'yyyy-MM-dd HH:mm:ss'})"/>
			<span style="padding: 0 6px 0 2px;">至</span><input type="text" name ="endTime" id="endTime"  style="width: 150px;" class="input-style" onclick="WdatePicker({el:'endTime',minDate:'#F{$dp.$D(\'startTime\')}', dateFmt: 'yyyy-MM-dd HH:mm:ss'})"/></td>
			<td width="20px;"></td>	
		</tr>
		<tr>
			<td width ="10px;"></td>
			<td></td><td></td>
			<td width="30px;"></td>
			<td>手机号：</td><td><input type="text" name="mobilePhone"/> </td>
			<td width ="20px;"></td>
			<td>推广码：</td><td><input type="text" name="shareCode"/> </td>
			<td width ="20px;"></td>			
			<td><a class="easyui-linkbutton" id="search" iconCLs="icon-search"  onclick="searchTable()">搜索</a></td>
			<td><a class="easyui-linkbutton" iconCls="icon-undo" onclick="document.getElementById('searchForm').reset();reload();">清空</a></td>
			<td width="10px;"></td>
			
		</tr>
	</table>
	</form>
	</div>
	<div region="center">
	<!-- datagrid信息表 -->
	<table id="datagrid_table"></table>
	<!-- 添加记录 -->
	<style>
		#datagrid_add,#datagrid_update{
			padding:  10px 20px;
		}
	
		#datagrid_add tr,#datagrid_update tr{
		    height: 30px;
		}
		
	</style>
	<div id="datagrid_add">
		<form id="add_form" action="../maintain/partnerInfo/add.do" method="post">
			<input type ="hidden" id="roleId" name="roleId">
			<table width="630" class="xxl_tb_1">
				<tbody>	
					
					<tr>
						<td colspan="3" style="text-align: center">					
							<a class="easyui-linkbutton" iconCls="icon-ok" onclick="addFormSubmit()">添加</a>
							<a class="easyui-linkbutton" iconCls="icon-undo" onclick="document.getElementById('add_form').reset()">重置</a>
							<a class="easyui-linkbutton" iconCls="icon-cancel" onclick="$('#datagrid_add').window('close');">取消</a>
						</td>
					</tr>
				</tbody>
			</table>
		</form>
	</div>
	
	<!-- 修改记录 -->
	<div id="datagrid_update">
		<form id="update_form" action="../maintain/partnerInfo/edit.do" method="post">
			<input type="hidden" id="idUpdate" name="id"/>
			<table width="630" class="xxl_tb_1">
				<tbody>
					<tr>
						<td class="xxl_td_2">昵称：</td>
						<td><div id="distributorNameUpdate" ></div></td>
					</tr>
					<tr>
						<td width="120" class="xxl_td_2">推广码：</td>
						<td><div id="shareCodeUpdate" ></div></td>
					</tr>
					<tr>
						<td class="xxl_td_2">资格：</td>
						<td><div id="distributorTypeUpdate" ></div></td>
					</tr>
					<tr>
						<td class="xxl_td_2">分成比例：</td>
						<td><input type="text" id="sharingProportionUpdate" name="sharingProportion" class="easyui-numberbox" min="0" precision="2" max="1" /></td>
					</tr>
					
					<tr>
						<td colspan="3" style="text-align: center">
							<a class="easyui-linkbutton" iconCls="icon-ok" onclick="updateFormSubmit()">修改</a>		
							<a class="easyui-linkbutton" iconCls="icon-cancel" onclick="$('#datagrid_update').window('close');">取消</a>
						</td>
					</tr>
				</tbody>
			</table>
		</form>
	</div>
</body>
</html>